package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IDongtaiService;
import com.ruoyi.system.service.IDongtaihudongService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Dongtaihudong;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 动态互动管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/dongtaihudong")
public class DongtaihudongController extends BaseController
{
    private String prefix = "system/dongtaihudong";

	@Autowired
	private IDongtaihudongService dongtaihudongService;
	@Autowired
	private IDongtaiService dongtaiService;

	@RequiresPermissions("system:dongtaihudong:view")
	@GetMapping()
	public String dongtaihudong()
	{
	    return prefix + "/dongtaihudong";
	}
	
	/**
	 * 查询动态互动管理列表
	 */
	@RequiresPermissions("system:dongtaihudong:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Dongtaihudong dongtaihudong)
	{
		startPage();
        List<Dongtaihudong> list = dongtaihudongService.selectDongtaihudongList(dongtaihudong);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出动态互动管理列表
	 */
	@RequiresPermissions("system:dongtaihudong:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Dongtaihudong dongtaihudong)
    {
    	List<Dongtaihudong> list = dongtaihudongService.selectDongtaihudongList(dongtaihudong);
        ExcelUtil<Dongtaihudong> util = new ExcelUtil<Dongtaihudong>(Dongtaihudong.class);
        return util.exportExcel(list, "dongtaihudong");
    }
	
	/**
	 * 新增动态互动管理
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("dongtais",dongtaiService.selectDongtaiList(null));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存动态互动管理
	 */
	@RequiresPermissions("system:dongtaihudong:add")
	@Log(title = "动态互动管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Dongtaihudong dongtaihudong)
	{
		SysUser user = getSysUser();
		dongtaihudong.setHuDongPersonId(user.getUserId());
		dongtaihudong.setStatus(0);//0为未关闭，1为关闭
		return toAjax(dongtaihudongService.insertDongtaihudong(dongtaihudong));
	}

	/**
	 * 修改动态互动管理
	 */
	@GetMapping("/edit/{dongtaihudongId}")
	public String edit(@PathVariable("dongtaihudongId") Integer dongtaihudongId, ModelMap mmap)
	{
		Dongtaihudong dongtaihudong = dongtaihudongService.selectDongtaihudongById(dongtaihudongId);
		mmap.put("dongtaihudong", dongtaihudong);
		mmap.put("hudongs",dongtaiService.selectByHuDongId(dongtaihudongId));
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存动态互动管理
	 */
	@RequiresPermissions("system:dongtaihudong:edit")
	@Log(title = "动态互动管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Dongtaihudong dongtaihudong)
	{		
		return toAjax(dongtaihudongService.updateDongtaihudong(dongtaihudong));
	}
	
	/**
	 * 删除动态互动管理
	 */
	@RequiresPermissions("system:dongtaihudong:remove")
	@Log(title = "动态互动管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(dongtaihudongService.deleteDongtaihudongByIds(ids));
	}
	
}
